package com.example.week6_udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		findViewById(R.id.button1).setOnClickListener(
				
		new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				new Network().start();
							
			}
		});
	
	}
	
	class Network extends Thread{
		@Override
		public void run() {
			//String IP="211.183.2.158";
			String IP="211.183.3.192";
			int PORT = 7000;
			
			try{
				InetAddress address=InetAddress.getByName(IP);
				
				DatagramSocket socket = new DatagramSocket();
				String message = "Hello UDP SERVER";
				byte[] b = message.getBytes();
				DatagramPacket packet = new DatagramPacket(b, b.length, address , PORT);
				socket.send(packet);
			}
			catch(Exception e){
				
			}
			
		}
		
	}

}
